using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Content;

namespace ParticleEngineDemo
{
    public class ParticleEngineDemo : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        public static SpriteBatch spriteBatch;

        Effects.ParticleEngine pEngine;
        Texture2D[] particles;

        public ParticleEngineDemo()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            base.Initialize();
            this.graphics.PreferredBackBufferWidth = 800;
            this.graphics.PreferredBackBufferHeight = 600;
            this.graphics.ApplyChanges();

        }

        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);


            // init particle engine
            particles = new Texture2D[4];
            particles[0] = Content.Load<Texture2D>("star1");
            particles[1] = Content.Load<Texture2D>("star2");
            particles[2] = Content.Load<Texture2D>("star3");
    

            pEngine = Effects.ParticleEngine.GetInstance();
            pEngine.textures = particles;
        }

        protected override void UnloadContent() { }

        int test = 0;
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
                       
            test ++;
            if (test % 80 == 0)
            {
                int max = (int)Effects.EffectFactory.EffectType.NUM_EFFECTS;
                const int border = 100;
                pEngine.StartEffect(
                    //Effects.EffectFactory.EffectType.POWER_FROM_ETHER,
                    (Effects.EffectFactory.EffectType)MyMaths.rand.Next(max),
                    new Vector2(border + MyMaths.rand.Next(800-(border*2)), border + MyMaths.rand.Next(600-(border*2))), 
                    0
                );
            }

            pEngine.Update();
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin();

            pEngine.Draw(spriteBatch);

            spriteBatch.End();
            base.Draw(gameTime);
        }
    }

    
}
